//
//  DXVisitorViewController.swift
//  新浪微博
//
//  Created by dix on 2017/1/18.
//  Copyright © 2017年 dix. All rights reserved.
//

import UIKit

class DXVisitorViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
        //判断用户登录
        let isLogin : Bool = DXOAuthViewModel.shared.isLogin
        //定义访客视图View 也可以使用懒加载 (可选值和懒加载都有延迟创建的特点)
    lazy var tableView: UITableView = UITableView()
        var visitorView : DXVisitorView?
        override func loadView(){
            if isLogin {
                view = tableView
            }else{
                //未登录
                setUPVisitorView()
            
            }
        }
        
        //实例化visitorView
       private func setUPVisitorView(){
            //未登录的状态创建导航按钮
            setUpNAV()
            visitorView = DXVisitorView()
            //实例化闭包
            visitorView?.closure = {[weak self] in
                self?.loginClick()
            }
            view = visitorView
        }
    
    func setUpNAV(){
        //左侧
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "登录", targrt: self, action: #selector(loginClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", targrt: self, action: #selector(loginClick))
        
    }
    func loginClick(){
        let oauthVC = DXOAuthViewController()
        //模态弹出控制器
    self.present(DXNavigationController(rootViewController : oauthVC), animated: true, completion: nil)
        
    }
}
